package com.spc.boot.common.secure;


import com.spc.boot.common.secure.enums.SecureType;

import java.io.InputStream;
import java.security.MessageDigest;

/**
 * MD5 单向加密
 * @author ghliu
 * @create 2019-03-20 19:47
 **/
public class MD5Secure extends BaseSecure
{
	@Override
	public byte[] encrypt(byte[] data) throws Exception
	{
		MessageDigest messageDigest = MessageDigest.getInstance(SecureType.MD5.getType());
		return messageDigest.digest(data);
	}

    @Override
    public byte[] decrypt(byte[] data) throws Exception {
        return null;
    }

	public byte[] encrypt(InputStream fis) throws Exception {
		MessageDigest md = MessageDigest.getInstance("MD5");
		byte[] buffer = new byte[2048];
		int length = -1;
		while ((length = fis.read(buffer)) != -1) {
			md.update(buffer, 0, length);
		}
		return md.digest();
	}
}
